package com.apestech.framework.xml.pub;

import org.apache.log4j.Logger;
import org.junit.Test;

import com.apestech.framework.json.JSONObject;
import com.apestech.framework.xml.pub.core.ElementUtil;


/**
 * 获取XML转JSON应用层,功能入口
 * @author hupo
 *
 */
public class XmlToJson extends ElementUtil {
	
	private static final Logger logger = Logger.getLogger(XmlToJson.class);
	
	@Test
	public void xmlToJson() throws Exception{
		String filename="D:/XML/SYS_CXDYB/SYS/qryRPT_AQKCQKRBB.sql";
		//filename="D:/sql/V_SYS_TABLE/ERP.sql";
		//xmlToJson(filename);
		filename="D:/XML/SYS_CXDYB/SYS/qryJJRKTJB.sql";
		filename="C:/Users/hup/Downloads/SER_FWFAD.bpmn20.sql";
		filename="D:/xmlM/MENU_TREE.XML";
		xmlToJson(filename);
	}
	
	/**
     * 从读取文件方式获取XML源文件,转换成JSON格式
     * @param filename String
     * @throws Exception 
	 */
	public JSONObject xmlToJson(String filename) throws Exception{
		/*XmlDataModel xmldat=new XmlDataModel();
		ReadXml sql=new ReadXml(xmldat);
		try {
			xmldat.setXmlFieldName(filename);
			sql.loadXmlFromFile();
			JSONObject map=new JSONObject();
			toJson(sql.getRoot(),map,true);
			logger.info(map);
			return map;
		} catch (Exception e) {
			throw new Exception(e.getMessage());
		} finally {
			xmldat=null;
			sql=null;
		}*/
		return null;
	}	
	
	/**
     * 从读取文件方式获取XML源文件,转换成JSON格式
     * @param filename String
     * @throws Exception 
	 */
	public JSONObject xmlToJsonAttr(String filename) throws Exception{
		/*XmlDataModel xmldat=new XmlDataModel();
		ReadXml sql=new ReadXml(xmldat);
		try {
			xmldat.setXmlFieldName(filename);
			sql.loadXmlFromFile();
			JSONObject map=new JSONObject();
			toJsonAttr(sql.getRoot(),map,true);
			logger.info(map);
			return map;
		} catch (Exception e) {
			throw new Exception(e.getMessage());
		} finally {
			xmldat=null;
			sql=null;
		}
		*/
		return null;
	}
	
	/**
     * 从读取文件方式获取XML源文件,转换成JSON格式
     * @param filename String
     * @throws Exception 
	 */
	public JSONObject xmlToJsonAttrJson(String filename) throws Exception{
		/*XmlDataModel xmldat=new XmlDataModel();
		ReadXml sql=new ReadXml(xmldat);
		try {
			xmldat.setXmlFieldName(filename);
			sql.loadXmlFromFile();
			JSONObject map=new JSONObject();
			getNodeAttrJson(sql.getRoot(),map,true);
			logger.info(map);
			return map;
		} catch (Exception e) {
			throw new Exception(e.getMessage());
		} finally {
			xmldat=null;
			sql=null;
		}*/
		return null;
	}	
	
	/**
     * 读取字串方式获取XML源文件,转换成JSON格式
     * @param xmlstr String
     * @throws Exception 
	 */
	public void xmlStrToJson(String xmlstr) throws Exception{
		/*XmlDataModel xmldat=new XmlDataModel();
		ReadXml sql=new ReadXml(xmldat);
		try {
			xmldat.setXmlString(xmlstr);
			sql.loadXmlFromString();
			JSONObject map=new JSONObject();
			toJson(sql.getRoot(),map,true);
			logger.info(map);
		} catch (Exception e) {
			throw new Exception(e.getMessage());
		} finally {
			xmldat=null;
			sql=null;
		}*/
	}
	
}
